// newHousePackage/pages/newHouseList/newHouseList.js

import { queryNewHouseByCondition } from "../../../service/house_service"
import { attentionAction } from "../../../service/attention_service"

import debounce from "../../../tools/debounce"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeStyle: "",
    requestData: {
      page: 0,
      pageSize: 10,
    },
    filterLsit: [],
    houseList: [],
    isBottomShow: false,
    isShowLoading: false,
    scrollRefreshStatus: true,
    tagName: "",
    searchWords: "",//搜索关键词
    selectCommunityNumber: "",//选中的小区number
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.themeStyle) {
      this.setData({
        themeStyle: app.globalData.themeStyle
      })
    }
  },
  //搜索操作:
  searchAction(e) {
    this.setData({
      searchWords: e.detail.searchWord,
      'requestData.page': 0,
      isBottomShow: false,
    })
    
  },

  //条件查询小区:
 
  //列表点击回调;
  communityAction(e) {
    console.log("JJLog:列表回调:" + JSON.stringify(e));
    let detail = e.detail;
    wx.navigateTo({
      url: '/secondHousePackage/pages/communitySaleHouseList/communitySaleHouseList?number=' + detail.number + "&name=" + detail.name,
    })

  },






  //滚动到底:
  scrolltolower() {
    if (this.data.isBottomShow) {
      //已经到底了就不加载了
      return;
    }
    let tempPage = this.data.requestData.page + 1;
    this.setData({
      'requestData.page': tempPage,
      isShowLoading: true,
    })
    
  },

  //scroll下拉刷新:
  refreshDownData() {
    console.log("JJLog:下拉刷新来了=====:");
    this.setData({
      scrollRefreshStatus: true,
      'requestData.page': 0,
      isBottomShow: false,
    })
    
  },

  //点赞操作:
  collectAction(e) {
    let { data, index } = e.detail;
    this.attentionAction(data, index);
  },

  //关注操作
  attentionAction(item, index) {
    let data = {
      collectType: 1,
      number: item.houseNumber
    }
    wx.showLoading();
    attentionAction(data).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        item.isCollect = !item.isCollect;
        //动态数组:
        let changeItem = 'houseList[' + index + '].isCollect';
        this.setData({
          [changeItem]: item.isCollect,
        })
        wx.showToast({
          title: item.isCollect ? "关注成功" : "取关成功",
          icon: "none"
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "操作失败",
        icon: "none"
      })
      console.error("JJLog:attentionAction", err);
    })
  },





  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


})